<?php $this->headLink()->prependStylesheet('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.15/themes/base/jquery-ui.css');?>
<?php $this->headScript()->prependFile(Ac_Util::getImageBaseUrl('/js/admin_script.v-'.AC_VERSION.'.js'))?>
<?php $this->headScript()->prependFile('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js')?>
<?php $this->headStyle()->captureStart()?>
    #content td { padding:5px}
    #content table { border:1px #aaa solid; padding:5px; width:100%}
    #content th {font-weight:bold;}
    #content .page a {padding:2px;}
    .range { width:100px; }
<?php $this->headStyle()->captureEnd()?>
<form method="get" name="user_form">
    <a href="<?php echo $this->geturl('add','user', null, 'admin1')?>">Add</a>
    Keyword : <input type="text" name="user" id="search" value="<?php if (!empty($_GET['user'])) { echo $_GET['user']; }?>"/>
    <label for="from">From </label>
	<input type="text" id="from" name="from" class="range"/>
	<label for="to"> To </label>
	<input type="text" id="to" name="to" class="range"/>
    <input type="submit" name="search_btn" id="search_btn" value="Search"/>
    <?php if (!empty($_GET['user'])) { ?>
        <a href="<?php echo $this->geturl('list','user', null, 'admin1')?>">View All</a>
    <?php } ?>
    <a href="user/extract-active<?php if(!empty($_GET['from']) && !empty($_GET['to'])){echo '?from='.$_GET['from'].'&to='.$_GET['to'];}?>">Active User Report</a> | <a href="user/extract-banned<?php if(!empty($_GET['from']) && !empty($_GET['to'])){echo '?from='.$_GET['from'].'&to='.$_GET['to'];}?>">Banned User Report</a> | <a href="user/extract-movie">Campaign 10</a> | <a href="user/extract-movie-with-q">Camapaign 6</a>
</form>
get Report for  
<a href="/admin/user/extract-data?start=<?php echo date('Y-m-d')?>&end=<?php echo date('Y-m-d')?>">Today</a>, 
<a href="/admin/user/extract-data?start=<?php echo date('Y-m-d', strtotime('yesterday'))?>&end=<?php echo date('Y-m-d', strtotime('yesterday'))?>" >Yesterday</a> 
<table border="1" id="listings">
<?php
    $get = $_GET; unset($get['page']);
    $pagination = $this->pagination($this->listing_number, $this->page, 30, 4, $this->geturl('list', 'user', null, 'admin1', $get));
?>
<?php if($this->listing_number == 0):?>
	No user are defined
<?php else:?>
    <tr>
        <th>
        </th>
        <th>
            <a href="<?php echo $this->geturl('list', 'user', null, 'admin1', array('sort' => 'email', 'page' => $this->page))?>">Email</a>
        </th>
        <th>
            User
        </th>
        <th>
            Type Account
        </th>
        <th>
            Posted Ads
        </th>
        <th>
            Newsletter
        </th>  
		<th>
            Message
        </th>       
        <th>
            <a href="<?php echo $this->geturl('list', 'user', null, 'admin1', array('sort' => 'recent', 'page' => $this->page))?>">Creation date</a>
        </th>
        <th>
            Status
        </th>
    </tr>
    <?php foreach ($this->list as $user):?>
        <tr>
        <?php $item = Model_User::find($user->id);?>
            <td>
                <a href="<?php echo $this->geturl('display', 'user', null, 'admin1', array('id'=> $item->_id))?>" target="_blank">Display</a>
            </td> 
            <td>
                <a href="<?php echo $this->geturl('display', 'user', null, 'admin1', array('id'=> $item->_id, 'bp'=>(empty($_GET['page'])? "" : $_GET['page'])))?>" target="_blank">
                    <?php echo htmlentities($item->email, ENT_COMPAT, 'utf-8'); ?>
                </a>
            </td>
            <?php if (!empty($item->username)):?>
                <td>
                    <?php echo htmlentities((string)$item->username, ENT_COMPAT, 'utf-8'); ?>
                </td>
            <?php else:?>
                <td>&nbsp;</td>
            <?php endif;?>
            <td>
                <?php if (!empty($item->cid)):?>
                        Company Admin
                <?php else:?>
                        Personal
                <?php endif;?>
            </td>
            <td>
                <?php
                $count_ads = Model_Listing::all(array('us' => new MongoId($item->_id)))->count();
                echo $count_ads;
                ?>
            </td>
            <td>
                <?php
					$nl = Model_User::one(array('_id' => new MongoId($item->_id)));
					echo !empty($nl->nl) ? $nl->nl : 0;
				?>
            </td>
			<td>
                <?php 
                	$count = Model_Message::all(array('fo.email' => $item->email))->count();
					echo $count;
					
				?>
            </td>            
            <td>
                <?php echo date (MEDIUM_DATE_FORMAT, $item->created_at)?>
            </td>
            <td>
                <?php
                if ($item->status == Model_User::STATUS_ACTIVE) {
                    echo 'Active';
                }
                if ($item->status == Model_User::STATUS_BANNED) {
                    echo 'Banned';
                }
                if ($item->status == Model_User::STATUS_DELETED) {
                    echo 'Deleted';
                }
                ?>
            </td>
        </tr>
    <?php 
    endforeach; 
endif;
?>
</table>
<?php echo $pagination;?>
